package com.lagou.xml04;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;
import org.junit.Test;

import java.util.List;

/**
 * @author 尘
 * @data 2022/5/13 1:24
 */
public class TestXPatch {

    @Test
    public void test() throws DocumentException {
        SAXReader reader = new SAXReader();

        Document document = reader.read("J:\\jdbc_work\\xml_task03\\src\\com\\lagou\\xml04\\book.xml");

        // 查询所有节点

        List<Node> list1 = document.selectNodes("/books/book[@id = '01']//*");
        System.out.println("第一本");
        for (Node node : list1){

            System.out.println(node.getName() + ':' + node.getText());
        }

        List<Node> list2 = document.selectNodes("/books/book[@id = '02']//*");
        System.out.println("第二本");
        for (Node node : list2){
            System.out.println(node.getName() + ':' + node.getText());
        }

        List<Node> list3 = document.selectNodes("/books/book[@id = '03']//*");
        System.out.println("第三本");
        for (Node node : list3){
            System.out.println(node.getName() + ':' + node.getText());
        }

    }

}
